namespace Hrm.EntityFramework.MigrationsHrm
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.ClassMateExtentions",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Key = c.String(maxLength: 50),
                        Value = c.String(maxLength: 50),
                        Order = c.Int(nullable: false),
                        IsEnable = c.Boolean(nullable: false),
                        CreateDatetime = c.DateTime(),
                        CreateUserCode = c.String(maxLength: 50),
                        UpdateDatetime = c.DateTime(),
                        UpdateUserCode = c.String(maxLength: 50),
                        ClassMate_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ClassMates", t => t.ClassMate_Id)
                .Index(t => t.ClassMate_Id);
            
            CreateTable(
                "dbo.ClassMates",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 50),
                        Birthday = c.DateTime(),
                        Sex = c.Int(nullable: false),
                        Address = c.String(maxLength: 200),
                        ImageUrl = c.String(maxLength: 1000),
                        Phone = c.String(maxLength: 50),
                        Email = c.String(maxLength: 50),
                        QQ = c.String(maxLength: 10),
                        WeChat = c.String(maxLength: 50),
                        Company = c.String(maxLength: 50),
                        Description = c.String(maxLength: 2000),
                        IsEnable = c.Boolean(nullable: false),
                        CreateDatetime = c.DateTime(),
                        CreateUserCode = c.String(maxLength: 50),
                        UpdateDatetime = c.DateTime(),
                        UpdateUserCode = c.String(maxLength: 50),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Schools",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 50),
                        Description = c.String(maxLength: 2000),
                        IsEnable = c.Boolean(nullable: false),
                        CreateDatetime = c.DateTime(),
                        CreateUserCode = c.String(maxLength: 50),
                        UpdateDatetime = c.DateTime(),
                        UpdateUserCode = c.String(maxLength: 50),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Companies",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 50),
                        Description = c.String(maxLength: 2000),
                        IsEnable = c.Boolean(nullable: false),
                        CreateDatetime = c.DateTime(),
                        CreateUserCode = c.String(maxLength: 50),
                        UpdateDatetime = c.DateTime(),
                        UpdateUserCode = c.String(maxLength: 50),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Departments",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 50),
                        ParentId = c.Int(nullable: false),
                        Order = c.Int(nullable: false),
                        IsEnable = c.Boolean(nullable: false),
                        CreateDatetime = c.DateTime(),
                        CreateUserCode = c.String(maxLength: 50),
                        UpdateDatetime = c.DateTime(),
                        UpdateUserCode = c.String(maxLength: 50),
                        Company_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Companies", t => t.Company_Id)
                .Index(t => t.Company_Id);
            
            CreateTable(
                "dbo.Staffs",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ChineseName = c.String(),
                        EnglishName = c.String(),
                        Adddress = c.String(),
                        WorkNumber = c.String(),
                        Telephone = c.String(),
                        Email = c.String(),
                        IsEnable = c.Boolean(nullable: false),
                        CreateDatetime = c.DateTime(),
                        CreateUserCode = c.String(maxLength: 50),
                        UpdateDatetime = c.DateTime(),
                        UpdateUserCode = c.String(maxLength: 50),
                        Department_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Departments", t => t.Department_Id)
                .Index(t => t.Department_Id);
            
            CreateTable(
                "dbo.SchoolClassMates",
                c => new
                    {
                        School_Id = c.Int(nullable: false),
                        ClassMate_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.School_Id, t.ClassMate_Id })
                .ForeignKey("dbo.Schools", t => t.School_Id, cascadeDelete: true)
                .ForeignKey("dbo.ClassMates", t => t.ClassMate_Id, cascadeDelete: true)
                .Index(t => t.School_Id)
                .Index(t => t.ClassMate_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Staffs", "Department_Id", "dbo.Departments");
            DropForeignKey("dbo.Departments", "Company_Id", "dbo.Companies");
            DropForeignKey("dbo.SchoolClassMates", "ClassMate_Id", "dbo.ClassMates");
            DropForeignKey("dbo.SchoolClassMates", "School_Id", "dbo.Schools");
            DropForeignKey("dbo.ClassMateExtentions", "ClassMate_Id", "dbo.ClassMates");
            DropIndex("dbo.SchoolClassMates", new[] { "ClassMate_Id" });
            DropIndex("dbo.SchoolClassMates", new[] { "School_Id" });
            DropIndex("dbo.Staffs", new[] { "Department_Id" });
            DropIndex("dbo.Departments", new[] { "Company_Id" });
            DropIndex("dbo.ClassMateExtentions", new[] { "ClassMate_Id" });
            DropTable("dbo.SchoolClassMates");
            DropTable("dbo.Staffs");
            DropTable("dbo.Departments");
            DropTable("dbo.Companies");
            DropTable("dbo.Schools");
            DropTable("dbo.ClassMates");
            DropTable("dbo.ClassMateExtentions");
        }
    }
}
